

#import "CommonJson.h"
#import "RequestMethod.h"

static CommonJson *commonjson=nil;
@implementation CommonJson
@synthesize requestDict;

+(CommonJson *)sharedInstance
{
	//NSLog(@"sharedInstance");
	@synchronized(self)
	{
		if (!commonjson) {
			commonjson=[[CommonJson alloc] init];
			[commonjson initData];
			//commonjson.requestDict = [[NSMutableDictionary alloc] init];
		}
		return commonjson;
	}
	return nil;
}
- (void)initData {
	requestDict = [[NSMutableDictionary alloc] init];
}
- (void)requestToPath:(NSString *)path 
		   methodName:(NSString *)method
		   bodyString:(NSString *)body 
			targetObj:(id)target  
	 targetMethodName:(NSString *)targetMethod
		   notifiName:(NSString *)name {
	RequestMethod *request = [[RequestMethod alloc] init];
	request.urlPath = path;
	request.jsonMethodName = method;
	request.urlBody = body;
	request.notificationTarget = target;
	request.targetMethodName = targetMethod;
	request.notificationName = name;
	[request start];
//    NSLog(@"path:%@,method:%@,body:%@",path,method,body);
	[requestDict setObject:request forKey:name];
	//[request release];
}
- (void)removeTarget:(id)target notiName:(NSString *)name {
	[[NSNotificationCenter defaultCenter] removeObserver:target name:name object:nil];
	if ([requestDict objectForKey:name]) {
		RequestMethod *request = (RequestMethod *)[requestDict objectForKey:name];
		[request release];
	}
}


-(void)dealloc
{
	[requestDict release];
	[super dealloc];
}
@end
